<?php
namespace app\user\controller;

use app\common\controller\UserBase;
use think\facade\Request;
use think\facade\Db;
use think\facade\Session;

use app\user\model\Notice as Tongzhi;

class Notice extends UserBase
{
    protected $noAuth = ['notice','add'];
    
    //通知首页
    public function notice()
    {
        $today = Tongzhi::where('user_id', UserId())->where('status','0')->whereDay('datetime')->order('datetime asc,id desc')->select();
        $list = Tongzhi::where('user_id', UserId())->where('status','0')->order('datetime asc,id desc')->select();
        
        return $this->fetch('notice',['today'=>$today,'list'=>$list]);
    }
    //新增
    public function add()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $param['shop_id'] = ShopId();
            $param['user_id'] = UserId();
            //验证规则
            $verify = input('_verify', true);
            if($verify!='0'){
                try{
                    $this->validate($param, 'notice');
                }catch (\Exception $e){
                    $this->error($e->getMessage());
                }
            }
            Tongzhi::create($param);
            insert_user_log('新增通知');
            $this->success('操作成功');
        }
        return $this->fetch('save');
    }
    
    
    
}
